package Tool;

import Javabean.Staff;

import java.sql.*;

public class MySQL_StaffAdd {
    public static void staffadd(Connection conn, Staff staff) throws SQLException {

        //转换
        int Marrry;
        if(staff.isMarry().equals("已婚"))
        {
            Marrry = 1;
        }else {
            Marrry = 0;
        }

        //定义sql

        //查询

        String sql = "insert into staffsystem.staff(Name,Sex,Brithday,Age,Marry,Place,Staff,Level,Salary) values(?,?,?,?,?,?,?,?,?);";
        //获取执行psql的对象  PreparedStatement
        PreparedStatement pstmt = conn.prepareStatement(sql);
        //设置？的值
        pstmt.setString(1, staff.getName());
        pstmt.setString(2, staff.getSex());
        pstmt.setString(3, staff.getBrithday());
        pstmt.setInt(4, staff.getAge());
        pstmt.setInt(5,Marrry);
        pstmt.setString(6, staff.getPlace());
        pstmt.setString(7, staff.getStaff());
        pstmt.setInt(8, staff.getLevel());
        pstmt.setDouble(9, staff.getSalary());
        //执行sql语句
        pstmt.executeUpdate();

        //释放资源
        pstmt.close();

    }
}

